<?php

namespace app\common\enums;

use think\exception\ValidateException;

class CourseFullTypeEnum extends BaseEnum
{
    // 定义常量
    public const C_30 = '1';
    public const C_60 = '2';
    public const EXPERIENCE = '3';

    // 定义描述
    public array $description = [
        self::C_30 => '30分钟课',
        self::C_60 => '正式课',
        self::EXPERIENCE => '体验课',
    ];

    // 定义课时时长（分钟）ClassHourType
    public array $classHourType = [
        self::C_30 => ClassHourTypeEnum::C_30,
        self::C_60 => ClassHourTypeEnum::C_60,
        self::EXPERIENCE => null // 体验课的时长从配置中读取
    ];

    /**
     * 根据值获取课时时长（分钟）
     */
    public function getClassHourType($value)
    {
        return $this->classHourType[$value] ?? null;
    }

    /**
     * 获取课程时长（分钟）
     */
    public function getMinutes($value)
    {
        switch ($value) {
            case self::C_30:
                return 30;
            case self::C_60:
                return 60;
            case self::EXPERIENCE:
                return env('course.ec_duration', 60);
            default:
                throw new ValidateException('未知的课程类型');
        }
    }

    /**
     * 获取课程最低分钟间隔
     */
    public function getMinMinutes($value)
    {
        try {
            $minutes = $this->getMinutes($value);
        } catch (ValidateException $e) {
            throw new ValidateException($e->getMessage());
        }
        return $minutes + 30;
    }
}
